<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>isBefore() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>isBefore()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>isBefore()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/query/is-before/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/05-query/01-is-before.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().isBefore(Moment|String|Number|Date|Array);
moment().isBefore(Moment|String|Number|Date|Array, String);
</code></pre>

							</div>
<p>&#x68C0;&#x67E5;&#x4E00;&#x4E2A; moment &#x662F;&#x5426;&#x5728;&#x53E6;&#x4E00;&#x4E2A; moment &#x4E4B;&#x524D;&#x3002;
&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4F1A;&#x88AB;&#x89E3;&#x6790;&#x4E3A; moment&#xFF08;&#x5982;&#x679C;&#x5C1A;&#x672A;&#x89E3;&#x6790;&#xFF09;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isBefore(&apos;2010-10-21&apos;); // true
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x5C06;&#x7C92;&#x5EA6;&#x9650;&#x5236;&#x4E3A;&#x6BEB;&#x79D2;&#x4EE5;&#x5916;&#x7684;&#x5355;&#x4F4D;&#xFF0C;&#x5219;&#x5C06;&#x5355;&#x4F4D;&#x4F5C;&#x4E3A;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4F20;&#x5165;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x7528;&#x4E8E;&#x786E;&#x5B9A;&#x7CBE;&#x5EA6;&#xFF0C;&#x4E14;&#x4E0D;&#x4EC5;&#x4EC5;&#x662F;&#x8981;&#x68C0;&#x67E5;&#x7684;&#x5355;&#x4E2A;&#x503C;&#xFF0C;&#x56E0;&#x6B64;&#x4F7F;&#x7528; day &#x5C06;&#x4F1A;&#x68C0;&#x67E5;&#x5E74;&#x4EFD;&#x3001;&#x6708;&#x4EFD;&#x3001;&#x65E5;&#x671F;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isBefore(&apos;2010-12-31&apos;, &apos;year&apos;); // false
moment(&apos;2010-10-20&apos;).isBefore(&apos;2011-01-01&apos;, &apos;year&apos;); // true
</code></pre>
<p>&#x4E0E; <code>moment#isAfter</code> &#x548C; <code>moment#isSame</code> &#x4E00;&#x6837;&#xFF0C;<code>moment#startOf</code> &#x652F;&#x6301;&#x7684;&#x4EFB;&#x4F55;&#x65F6;&#x95F4;&#x5355;&#x4F4D;&#x4E5F;&#x9002;&#x7528;&#x4E8E; <code>moment#isBefore</code>&#x3002;</p>
<pre><code>year month week isoWeek day hour minute second
</code></pre>
<p>&#x5982;&#x679C;&#x672A;&#x5C06;&#x4EFB;&#x4F55;&#x5185;&#x5BB9;&#x4F20;&#x7ED9; <code>moment#isBefore</code>&#xFF0C;&#x5219;&#x5B83;&#x5C06;&#x4F1A;&#x9ED8;&#x8BA4;&#x4E3A;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF1A;<code>moment().isBefore()</code> &#x5177;&#x6709;&#x672A;&#x5B9A;&#x4E49;&#x7684;&#x884C;&#x4E3A;&#xFF0C;&#x4E14;&#x4E0D;&#x5E94;&#x88AB;&#x4F7F;&#x7528;&#xFF01;
&#x5982;&#x679C;&#x4EE3;&#x7801;&#x8FD0;&#x884C;&#x5FEB;&#x901F;&#xFF0C;&#x5219;&#x521D;&#x59CB;&#x521B;&#x5EFA;&#x7684; moment &#x5C06;&#x4F1A;&#x4E0E;isBefore &#x4E2D;&#x521B;&#x5EFA;&#x7684;&#x8981;&#x6267;&#x884C;&#x68C0;&#x67E5;&#x7684;&#x76F8;&#x540C;&#xFF0C;&#x56E0;&#x6B64;&#x7ED3;&#x679C;&#x5C06;&#x4F1A;&#x4E3A; <code>false</code>&#x3002;
&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4EE3;&#x7801;&#x8FD0;&#x884C;&#x901F;&#x5EA6;&#x8F83;&#x6162;&#xFF0C;&#x5219;&#x6709;&#x53EF;&#x80FD;&#x5728; isBefore &#x4E2D;&#x521B;&#x5EFA;&#x7684; moment &#x53EF;&#x6D4B;&#x91CF;&#x5730;&#x5728; <code>moment()</code> &#x4E2D;&#x521B;&#x5EFA;&#x7684;&#x4E4B;&#x540E;&#xFF0C;&#x56E0;&#x6B64;&#x8BE5;&#x8C03;&#x7528;&#x5C06;&#x4F1A;&#x8FD4;&#x56DE; <code>true</code>&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().isBefore(Moment|String|Number|Date|Array);
moment().isBefore(Moment|String|Number|Date|Array, String);
</code></pre>

							</div>
<p>Check if a moment is before another moment. The first argument will be parsed as a moment, if not already so.</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isBefore(&apos;2010-10-21&apos;); // true
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.</p>
<p>As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isBefore(&apos;2010-12-31&apos;, &apos;year&apos;); // false
moment(&apos;2010-10-20&apos;).isBefore(&apos;2011-01-01&apos;, &apos;year&apos;); // true
</code></pre>
<p>Like <code>moment#isAfter</code> and <code>moment#isSame</code>, any of the units of time that are supported for <code>moment#startOf</code> are supported for <code>moment#isBefore</code>.</p>
<pre><code>year month week isoWeek day hour minute second
</code></pre>
<p>If nothing is passed to <code>moment#isBefore</code>, it will default to the current time.</p>
<p><em>NOTE</em>: <code>moment().isBefore()</code> has undefined behavior and should not be used! If
the code runs fast the initial created moment would be the same as the one
created in isBefore to perform the check, so the result would be <code>false</code>. But
if the code runs slower it&apos;s possible that the moment created in isBefore is
measurably after the one created in <code>moment()</code>, so the call would return
<code>true</code>.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>